package com.tangqi.android;

import java.text.DecimalFormat;

public class CalUtil {

	//个税起征点
	public static final int BASE_INCOME = 3500;
	
	
	/**
	 * 甲类计划    上限       下限
	 *			12900 1800
	 * 乙类计划   上限       下限
	 *	        11392 1800
	 */
	public static String checkBound(String fundType,double grossIncome){
		String warningMesageString = null;
		if("JIA".equals(fundType)&&grossIncome>12900){
			warningMesageString = "超过甲类缴费上限12900元";
		}
		if("JIA".equals(fundType)&&grossIncome<1800){
			warningMesageString = "低于甲类缴费下限1800元";
		}
		if("YI".equals(fundType)&&grossIncome>11392){
			warningMesageString = "超过乙类缴费上限11392元";
		}
		if("YI".equals(fundType)&&grossIncome<1800){
			warningMesageString = "低于乙类缴费下限1800元";
		}
		return warningMesageString;
	}
	
	public static double calculate(double income) {
		double taxbase = income - BASE_INCOME;
		double incomeTax = 0.00;
		if (taxbase <= 0) {
			return incomeTax;
		} else if (taxbase <= 500) {
			incomeTax = taxbase * 0.05;
		} else if (taxbase <= 2000) {
			incomeTax = taxbase * 0.1 - 25;
		} else if (taxbase <= 5000) {
			incomeTax = taxbase * 0.15 - 175;
		} else if (taxbase <= 20000) {
			incomeTax = taxbase * 0.2 - 375;
		} else if (taxbase <= 40000) {
			incomeTax = taxbase * 0.25 - 1375;
		} else if (taxbase <= 60000) {
			incomeTax = taxbase * 0.3 - 3375;
		} else if (taxbase <= 80000) {
			incomeTax = taxbase * 0.35 - 6375;
		} else if (taxbase <= 100000) {
			incomeTax = taxbase * 0.4 - 10375;
		} else {
			incomeTax = taxbase * 0.45 - 15375;
		}
		return tranFormat(incomeTax);
	}
	
	/*
	 *   2011年9月1日  新个人所得税计算办法
	 *   应纳税所得额                              税率                            速算扣除数(元)
	 *   不超过1500元                             税率为3%            0
	 *   1500元至4500元                       税率为10%           75
	 *   4500元至9000元                       税率为20%           525
	 *   超过9000元至35000元           税率为25%           975
	 *   超过35000元至55000元        税率为30%           2725
	 *   超过55000元至80000元        税率为35%           5475
	 *   超过80000元                               税率为45%           13475
    */
	public static double calculateIIT(double income) {
		double taxbase = income - BASE_INCOME;
		double incomeTax = 0.00;
		if (taxbase <= 0) {
			return incomeTax;
		} else if (taxbase <= 1500) {
			incomeTax = taxbase * 0.03;
		} else if (taxbase <= 4500) {
			incomeTax = taxbase * 0.1 - 75;
		} else if (taxbase <= 9000) {
			incomeTax = taxbase * 0.2 - 525;
		} else if (taxbase <= 35000) {
			incomeTax = taxbase * 0.25 - 975;
		} else if (taxbase <= 55000) {
			incomeTax = taxbase * 0.3 - 2725;
		} else if (taxbase <= 80000) {
			incomeTax = taxbase * 0.35 - 5475;
		} else {
			incomeTax = taxbase * 0.45 - 13475;
		}
		return tranFormat(incomeTax);
	}
	
	public static double tranFormat(double bf){
		return new Double(new DecimalFormat(".00").format(bf));
	}
}
